﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Models;
using System.IO;
namespace DAL
{
   public  class FileOperator
    {
       /// <summary>
       /// 
       /// 从文件中读取学生信息
       /// </summary>
       /// <param name="fileName"></param>
       /// <returns></returns>
       public List<Student> ReadFile(string fileName) {
           List<Student> ls = new List<Student>();
           string sr = string.Empty;
           try
           {
               StreamReader sreader = new StreamReader(fileName, Encoding.Default);
               sr = sreader.ReadLine();
               while (sr!=null){
                   string[] stu = sr.Split(',');
                   Student s = new Student();
                   s.Sno = stu[0];
                   s.Sname = stu[1];
                   s.Phone = stu[2];
                   s.Email = stu[3];
                   s.Sex = stu[4];
                   ls.Add(s);
                   sr = sreader.ReadLine();
               }
               sreader.Close();
           }
           catch (Exception ex)
           {
               
               throw ex;
           }

           return ls;
       }
    }
}
